<template>
  <div class="block">
    <span class="demonstration"></span>

    <el-date-picker
      value-format="timestamp"
      v-model="value2"
      type="datetimerange"
      :picker-options="pickerOptions"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      align="right"
    >
    </el-date-picker>
    <el-select v-model="searchForm.type" clearable placeholder="请选择类型">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <el-select v-model="searchForm.status" clearable placeholder="请选择状态">
      <el-option
        v-for="item in options1"
        :key="item.value1"
        :label="item.label1"
        :value="item.value1"
      >
      </el-option>
    </el-select>
    <el-select v-model="searchForm.userId" clearable placeholder="顾客编号">
      <el-option
        v-for="item in categoryData"
        :key="item.name"
        :label="item.name"
        :value="item.userId"
      >
      </el-option>
    </el-select>
    <el-button type="primary" @click="toSearch">查询</el-button>

    <el-table :data="categoryData" stripe style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"> </el-table-column>
      <el-table-column prop="transferMoney" label="交易金额" width="180">
      </el-table-column>
      <el-table-column prop="transferTime" label="交易时间">
        <template slot-scope="scope">
          <!-- <el-tag v-if="scope.row.status==='正常'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.status}}</el-tag>-->
          <!-- scope.row.status==='正常'?'success':'danger' -->
          <el-tag>{{ scope.row.transferTime | fmtDateTime }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="type" label="交易类型"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <!-- <el-tag v-if="scope.row.status==='正常'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else type="danger">{{scope.row.status}}</el-tag>-->
          <!-- scope.row.status==='正常'?'success':'danger' -->
          <el-tag :type="scope.row.status === '正常' ? 'success' : 'danger'">{{
            scope.row.status
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="description" label="描述"> </el-table-column>
    </el-table>
    <div class="block" style="float: right">
      <span class="demonstration"></span>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.page"
        :page-sizes="[2, 5, 10, 15, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { pageQuery } from "@/api/Custome";
import { pageQuerypro } from "@/api/CustomePro";

export default {
  data() {
    return {
      total: 0,

      searchForm: {
        type: "",
        status: "",
        userID: "",
      },

      params: {
        page: 1,
        pageSize: 10,
      },

      categoryData: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      value2: "",

      options: [
        {
          value: "充值",
          label: "充值",
        },
        {
          value: "消费",
          label: "消费",
        },
      ],
      value: "",

      options1: [
        {
          value1: "正常",
          label1: "正常",
        },
        {
          value1: "未审核",
          label1: "未审核",
        },
      ],
      value1: "",

      tableData: [],
    };
  },
  watch: {
    // 深度监听分页参数
    params: {
      handler() {
        this.queryData();
      },
      deep: true,
    },
  },
  computed: {},
  methods: {
    handleSizeChange(val) {
      this.params = {
        page: 1,
        pageSize: val,
        total: 0,
      };
    },
    handleCurrentChange(val) {
      console.log(`每页 ${val} 条`);
      this.params.page = val;
    },

    async queryCategoryData() {
      let res = await pageQuery({ page: 1, pageSize: 100 });

      this.categoryData = res.data.list;
    },

    toSearch() {
      this.queryData();
    },
    async queryData() {
      this.loading = true;

      let temp = {
        ...this.params,
        ...this.searchForm,
      };
      temp.beginTime = this.value2[0];
      temp.endTime = this.value2[1];
      // 遍历对象
      for (let key in temp) {
        if (!temp[key]) {
          delete temp[key];
        }
      }

      let res = await pageQuerypro(temp);
      console.log(res.data);
      this.loading = false;
      console.log(res.data.list);
      this.categoryData = res.data.list;
      this.total = res.data.total;
    },
  },
  created(categoryData) {
    this.queryCategoryData(), this.toSearch();
  },
  mounted() {},
};
</script>
<style scoped>
</style>